home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <assert.h>
- #include <X11/Xlib.h>
- #include <X11/Xresource.h>
- #include <speech/Recognizer.h>
- #include <speech/Word.h>
- #include <speech/WordCallbackBindings.h>
- #include <speech/Vocabulary.h>
- #include <speech/Condition.h>
- #include <speech/Event.h>
- #include <speech/Error.h>
- #include <speech/Shorthand.h> /* required for C API */
-
- void doThis( const Event* event, void* v )
- {
- fprintf( stderr, "do this called with %d\n", Event_type( event )) ;
- fflush( stderr ) ;
- }
- void doThat( const Event* event, void* v )
- {
- fprintf( stderr, "do this called with %d\n", Event_type( event )) ;
- fflush( stderr ) ;
- }
- void doTheOther( const Event* event, void* v )
- {
- fprintf( stderr, "do this called with %d\n", Event_type( event )) ;
- fflush( stderr ) ;
- }
-
- void usage( const char* const progName )
- { fprintf( stderr, "usage <word1> <word2>\n" ) ; fflush( stderr ) ; }
-
- int main( int argc, char* argv[] )
- {
- XEvent event ;
-
- Window window ;
-
- Vocabulary* localWords ;
- Vocabulary* globalWords ;
-
- unsigned char swapConditionsUsingVocabularies = 0 ;
-
- char* applicationClass = "Recognize" ;
- char* applicationName = argv[0] ;
-
- char fileName[256] ;
- XrmDatabase xrmDatabase ;
-
- Recognizer* recognizer ;
-
- sprintf( fileName, "%s/.Xdefaults", getenv( "HOME" ) ) ;
- xrmDatabase = XrmGetFileDatabase( fileName ) ; /* toolkit-dependent */
-
- recognizer = Recognizer_new(
- applicationClass, applicationName, xrmDatabase,
- "", /* default display, program name */
- Recognizer_RecognitionInterest() /* recognition events */
- | Recognizer_RejectionInterest() /* and all others */
- | Recognizer_AmbiguousInterest()
- | Recognizer_ErrorInterest() ) ;
- assert( Recognizer_status( recognizer ) == Error_OK ) ;
-
- /* words with global focus */
- {
- ActionCallbackBinding globalActionFunctionBindings[] = {
- "doThis", doThis, (void*)0,
- "doThat", doThat, (void*)0,
- (char*)0, (CallbackFunctionPointer)0, (void*)0,
- } ;
-
- Condition* globalCondition = Condition_newGlobal() ;
- Recognizer_newWords( recognizer, globalActionFunctionBindings,
- globalCondition, &globalWords ) ;
- if( Recognizer_status( recognizer ) != Error_OK )
- { fprintf( stderr, "trouble loading global words\n" ) ; fflush( stderr ) ; }
- Condition_delete( globalCondition ) ;
- }
-
-
- /* words with window focus */
- {
- ActionCallbackBinding localActionFunctionBindings[] = {
- "doTheOther", doTheOther, (void*)0,
- (char*)0, (CallbackFunctionPointer)0, (void*)0,
- } ;
-
- /* toolkit dependent */
- void* v = "client data" ;
- int screen = DefaultScreen( Recognizer_dpy( recognizer ) ) ;
- Window root = RootWindow( Recognizer_dpy( recognizer ), screen ) ;
- long white = WhitePixel( Recognizer_dpy( recognizer ), screen ) ;
- long black = BlackPixel( Recognizer_dpy( recognizer ), screen ) ;
- window = XCreateSimpleWindow( Recognizer_dpy( recognizer ), root,
- 100, 100, 100, 100, 1, white, black ) ;
- XMapWindow( Recognizer_dpy( recognizer ), window ) ;
-
- {
- Condition* localCondition = Condition_newWindow( window ) ;
- Recognizer_newWords( recognizer, localActionFunctionBindings,
- localCondition, &localWords ) ;
- if( Recognizer_status( recognizer ) != Error_OK )
- { fprintf( stderr, "trouble loading local words\n" ) ; fflush( stderr ) ; }
- Condition_delete( localCondition ) ;
- }
- }
-
- /* vocabulary usage */
- if( swapConditionsUsingVocabularies )
- {
- Condition* globalCondition = Condition_newGlobal() ;
- Condition* localCondition = Condition_newWindow( window ) ;
-
- Vocabulary_enable( localWords, globalCondition ) ;
- Vocabulary_enable( globalWords, localCondition ) ;
-
- Condition_delete( globalCondition ) ;
- Condition_delete( localCondition ) ;
- }
-
- Vocabulary_delete( globalWords ) ;
- Vocabulary_delete( localWords ) ;
-
- /* toolkit-dependent modification here */
- do
- {
- XNextEvent( Recognizer_dpy( recognizer ), &event ) ;
-
- fprintf( stdout, "event type = %d\n", event.type ) ;
- fflush( stdout ) ;
-
- if( Recognizer_isSpeechEvent( recognizer, &event ) )
- Recognizer_processEvent( recognizer, &event ) ;
- else
- ; /* process as other/normal event */
-
- } while( event.type != DestroyNotify ) ; /* just to get rid of warning */
-
- XrmDestroyDatabase( xrmDatabase ) ;
-
- {
- Error retVal = Recognizer_status( recognizer ) ;
- Recognizer_delete( recognizer ) ;
- return retVal ;
- }
- }
-